package com.oocl.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.oocl.entity.Orders;
import com.oocl.service.OrdersService;
import com.oocl.vo.OrdersVo;

@Controller
@RequestMapping("/orders")
public class OrdersController {

	@Resource(name="ordersService")
	private OrdersService ordersService;
	
	@RequestMapping(value="/findAll",method=RequestMethod.GET)
	@ResponseBody
	public List<OrdersVo> findAllOrdersByMerchant(HttpSession session){
		return ordersService.findAllOrdersByIcnum((String)session.getAttribute("icnum"));
	}
	
	@RequestMapping(value="/findUnreceived",method=RequestMethod.GET)
	@ResponseBody
	public List<OrdersVo> findUnreceivedByMerchant(HttpSession session){
		return ordersService.findUnreceivedOrdersByIcnum((String)session.getAttribute("icnum"));
	}
	
	@RequestMapping(value="/findRefused",method=RequestMethod.GET)
	@ResponseBody
	public List<OrdersVo> findRefusedByMerchant(HttpSession session){
		return ordersService.findRefusedOrdersByIcnum((String)session.getAttribute("icnum"));
	}
	
	@RequestMapping(value="/findReceived",method=RequestMethod.GET)
	@ResponseBody
	public List<OrdersVo> findReceivedByMerchant(HttpSession session){
		return ordersService.findRefusedOrdersByIcnum((String)session.getAttribute("icnum"));
	}
	
	@RequestMapping(value="/findFinished",method=RequestMethod.GET)
	@ResponseBody
	public List<OrdersVo> findFinishedByMerchant(HttpSession session){
		return ordersService.findFinishedOrdersByIcnum((String)session.getAttribute("icnum"));
	}
	
	@RequestMapping(value="/findDelivering",method=RequestMethod.GET)
	@ResponseBody
	public List<OrdersVo> findDeliveringByMerchant(HttpSession session){
		return ordersService.findDeliveringOrdersByIcnum((String)session.getAttribute("icnum"));
	}
	
	@RequestMapping(value="/receiveOrder",method=RequestMethod.GET)
	@ResponseBody
	public List<OrdersVo> receiveOrders(String oid){   //接单操作
		
		return ordersService.updateOrdersStatus(oid, "1");
	}
	
	@RequestMapping(value="/refuseOrder",method=RequestMethod.GET)
	@ResponseBody
	public List<OrdersVo> refuseOrders(String oid){   //拒单操作
		
		return ordersService.updateOrdersStatus(oid, "2");
	}
	
	@RequestMapping(value="/deliverOrder",method=RequestMethod.GET)
	@ResponseBody
	public List<OrdersVo> deliverOrders(String oid){   //配送操作
		
		return ordersService.updateOrdersStatus(oid, "3");
	}
	
	
	@RequestMapping(value="/findOrderDetailInfo",method=RequestMethod.GET)
	@ResponseBody
	public List<OrdersVo> findOrderDetailInfo(String oid){
		return ordersService.findOrdersByOId(oid);
	}
	
	
	
	
}
